<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">

		<style type="text/css">
			#provider {
				margin-left: 16%;
			}
		</style>
	</head>

	<body style="padding:0px;background-color: white">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div>
			<form id="ff" method="post">
				<table id="basicInfo" cellpadding="5" class="displaytable" style="text-align: left;">
					<tr>
						<td width="15%">
							<h id="star">* </h>租户姓名</td>
						<td width="35%">
							<input class="easyui-combobox" style="width: 100%;" name="TENANT_NAME" id="input_TENANT_NAME" data-options="required:true" />
						</td>
						<!--<td width="15%">
							<h id="star">* </h>缴费时间</td>
						<td width="35%">
							<input class="easyui-datebox " style="width: 100%" name="COST_DATE" id="input_COST_DATE" data-options="required:true" />
						</td>-->
						
						<td width="15%">
							<h id="star">* </h>缴费人</td>
						<td width="35%">
							<input class="easyui-textbox" style="width:100%;" type="text" name="PAYER" id="input_PAYER" data-options='required:true' />
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>收费类型</td>
						<td>
							<input class="easyui-combobox" style="width: 100%" name="CHARGETYPE" id="input_CHARGETYPE" data-options="required:true" />
						</td>
						<td>
							<h id="star">* </h>费用名称</td>
						<td>
							<input class="easyui-combobox" style="width:100%;" type="text" name="CHARGENAME" id="input_CHARGENAME" data-options="required:'true'" />
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>应收金额</td>
						<td>
							<input class="easyui-numberbox " style="width: 100%;" type="text" name="SUM" id="input_SUM" data-options='required:true,precision:2' />
						</td>
						<td>
							<h id="star">* </h>实收金额</td>
						<td>
							<input class="easyui-numberbox " style="width: 100%;" type="text" name="REAL_SUM" id="input_REAL_SUM" data-options='required:true,precision:2' />
						</td>

					</tr>
					<tr>
						
					</tr>
					<tr style="display: none">
						<td>
							<h id="star">* </h>收费单据ID</td>
						<td>
							<input class="easyui-textbox" value="0" style="width:100%;" type="text" name="FEEORDER_ID" id="input_FEEORDER_ID" />
						</td>
						<td>
							<h id="star">* </h>收费单据的类型</td>
						<td>
							<input class="easyui-textbox" style="width: 100%;" type="text" id="input_FEEORDER_TYPE" name="FEEORDER_TYPE" />
						</td>
					</tr>
					<tr id="nodisplay" style="display: none">
						<td>
							<h id="star">* </h>ID</td>
						<td>
							<input class="easyui-textbox" style="width: 100%;" type="text" id="input_ID" data-options="required:true" name="ID" />
						</td>
						<td>
							<h id="star">* </h>租户编号</td>
						<td>
							<input class="easyui-textbox" style="width: 100%;" type="text" id="input_TENANT_ID" name="TENANT_ID" />
						</td>

					</tr>
				</table>
				<div id="new_footer" style="bottom: 0;">

				</div>
			</form>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 40%;height: 450px;" frameborder="0" scrolling="no"></iframe>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/finance.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.edatagrid.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/json2.js"></script>
	<script type="text/javascript" src="../../../JS/FrozenShareFunction/FrozenShare.js"></script>
	<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	<script type="text/javascript">
		var currid = AddFlag;
		var content = "";
		var currPage = 0; //当前的页数
		var MaxPage = 0;
		var MinPage = 1;
		var isVerify = 0;
		var FEE_IN_TYPE = 0;
		var FEE_OUT_TYPE = 1;
		var FEE_PACKAGE_TYPE = 2;
		var FEE_OTHER_TYPE = 3;
		var currFeeType;
		var saveUrl = "";
		var parentPage = "";
		getPageMaxAndMin();
		addDialogFooter($("#new_footer"));

		var detailData = [{
			"icon": "icon-undo",
			"func": "cls()",
			"functionname": "清空"
		}]
		var receipts_type = RECEIPT_FRONT_SYMBOL;
		receipts_type += RECEIPT_NEXT_SYMBOL;
		receipts_type += RECEIPT_ADD_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL;
		receipts_type += RECEIPT_DELETE_SYMBOL;
		receipts_type += RECEIPT_VERIFY_SYMBOL;
		receipts_type += RECEIPT_UNVERIFY_SYMBOL;
		receipts_type += RECEIPT_PRINT_SYMBOL;
		receipts_type += RECEIPT_SEARCH_SYMBOL;
		receipts_type += RECEIPT_EXPORT_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, detailData);
		$("#toolbar").append(content);

		createTenantCombobox();
		var datas = getMultiID();
		var ID = datas.id;
		var type = datas.type;
		$(document).ready(function(){
			if((ID != null || ID != undefined) && (type != null || type != undefined)) {
				checkRemoteData();
			}
		})

		$('#input_CHARGETYPE').combobox({
			valueField: 'value',
			textField: 'text',
			panelHeight: 'auto',
			data: [{
				"value": "0",
				"text": "收费"
			}, {
				"value": "1",
				"text": "退费"
			}, {
				"value": "3",
				"text": "充值"
			}]

		});

		$("#input_CHARGENAME").combobox({
			valueField: 'TYPE',
			textField: 'TYPE',
			panelHeight: 200,
			mode: 'remote',
			method: 'get',
			url: RemoteLinkAddress + "/frozen/chargetype/listall.do",
		});

		function checkRemoteData() {
			var _url = "";
			switch(type) {
				case "in":
					_url = RemoteLinkAddress + '/frozen/inorder/findbyid.do?ID=' + ID;
					getRemoteData(_url, ID, FEE_IN_TYPE);
					currid = AddFlag;
					saveUrl = RemoteLinkAddress + '/frozen/inorder/charged.do';
					parentPage = "LeasingOperationAddInStorage.html";
					break;
				case "out":
					_url = RemoteLinkAddress + '/frozen/outorder/findbyid.do?ID=' + ID;
					getRemoteData(_url, ID, FEE_OUT_TYPE);
					currid = AddFlag;
					saveUrl = RemoteLinkAddress + '/frozen/outorder/charged.do';
					parentPage = "LeasingOperationAddOutStorage.html";
					break;
				case "package":
					_url = RemoteLinkAddress + '/frozen/contract/findbyid.do?ID=' + ID;
					getRemoteData(_url, ID, FEE_PACKAGE_TYPE);
					currid = AddFlag;
					saveUrl = RemoteLinkAddress + '/frozen/contract/charged.do';
					parentPage="PackageStoreHouseList.html";
					break;
				case "other":
					saveUrl = RemoteLinkAddress + "/frozen/charge/save.do";
					loadLocal(ID);
					parentPage="TenantChargeList.html";
					break;
			}

		}

		function getRemoteData(_url, Feeid, FeeType) {
			$.ajax({
				dataType: "json",
				type: "get",
				url: _url,
				success: function(result) {
					if(result != null) {
						if(FeeType == FEE_OUT_TYPE) {
							result.TENANT_NAME = result.CHARGER;
							result.TENANT_ID = result.CHARGER_ID;
							// $('#input_TENANT_NAME').textbox('setValue', result.CHARGER);
							// $('#input_TENANT_ID').textbox('setValue', result.CHARGER_ID);
						} else {
							// $('#input_TENANT_NAME').textbox('setValue', result.TENANT_NAME);
							// $('#input_TENANT_ID').textbox('setValue', result.TENANT_ID);
						}
						// $('#input_SUM').numberbox('setValue', result.SUM);
						// $('#input_REAL_SUM').numberbox('setValue', result.REAL_SUM);
						$('#input_FEEORDER_ID').textbox('setValue', Feeid);
						$('#input_FEEORDER_TYPE').textbox('setValue', FeeType);
						$('#ff').form('load', result);

					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/frozen/charge/getmaxminid.do";
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = result.MINID + 1;
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function newdata() { //新建
			$("#verifydisplay").empty(); //去掉审核或者未审核的图片
			isVerify = 0; //将状态改为未审核
			currid = AddFlag;
			currPage = 0;
			resetData();
		}

		//导出
		function exportExcel() {
			if(currid === AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						data: {
							"ID": currid
						},
						url: RemoteLinkAddress + "/frozen/charge/excelorder.do",
						dataType: "json", //服务器返回的数据类型
						success: function(result) {
							window.location.href = result.path;
							//							this.onClick(location = result.path);
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		function frontpage() { //上一张
			if(currPage > MinPage) {
				var _url = RemoteLinkAddress + '/frozen/charge/pre.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示", "没有上张");
			}
		}

		function nextpage() { //下一张
			if(currPage < MaxPage) {
				var _url = RemoteLinkAddress + '/frozen/charge/next.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert(" 提示", "没有下张");
			}
		}

		function searchmore() {
			AddTabIn("租户明细账查询", parent.parent.$('#tabs'), "UI/FrozenCave/TenantCharge/TenantChargeSearch.html");
		}

		function save() { //保存
			if(currid != AddFlag && isVerify == "1") {
				$.messager.alert('Info', '该单据已通过审核，不可修改！');
				return;
			}
			if($("input[name='TENANT_NAME']").val() == "" || $("input[name='COST_DATE']").val() == "" || $("input[name='CHARGETYPE']").val() == "" || $("input[name='CHARGENAME']").val() == "" || $("input[name='PAYER']").val() == "" || $("input[name='SUM']").val() == "") {
				$.messager.alert('提示信息', '信息不能为空!');
				return;
			}
			if(currid != AddFlag) {
				getUpdateData();
			} else {
				getSaveData();
			}
		}

		function deletedata() { //删除
			if(currid != AddFlag && isVerify === "1") {
				$.messager.alert("提示", "该单据已审核，不能删除！");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不能删除！");
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/charge/delete.do", {
							ID: currid,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({ // show success message
									title: '成功',
									msg: '删除成功'
								});
								nextpage();
							} else {
								$.messager.alert({ // show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function verifydata() { //审核
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可审核！");
				return;
			}
			if(isVerify === "1") {
				$.messager.alert("警告", "已经审核无须再审");
				return;
			}

			var _url = RemoteLinkAddress + "/frozen/charge/verify.do";
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: {
					ID: currid,
					CHARGETYPE: _dataPage.CHARGETYPE,
					SUM: _dataPage.SUM,
					TENANT_ID: _dataPage.TENANT_ID,
				},
				type: "POST",
				success: function(result) {
					$.messager.alert("成功", "审核成功");
					isVerify = "1";
					verifyStatus_Market(isVerify, true);
				},
				error: function(result) {
					$.messager.alert("失败", "审核失败");
				}
			});
		}

		function unverifydata() { //弃审
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可弃审！");
				return;
			}
			if(isVerify === "0") {
				$.messager.alert("警告", "已经弃审无须再弃审");
				return;
			}
			$.messager.confirm("警告", "你确认要弃审该条单据吗", function(r) {
				if(r) {
					var _url = RemoteLinkAddress + "/frozen/charge/unverify.do";
					$.ajax({
						dataType: 'JSON',
						url: _url,
						data: {
							ID: currid,
							CHARGETYPE: _dataPage.CHARGETYPE,
							SUM: _dataPage.SUM,
							TENANT_ID: _dataPage.TENANT_ID,
						},
						type: "POST",
						success: function(result) {
							$.messager.alert("成功", "弃审成功");
							isVerify = "0";
							verifyStatus_Market(isVerify, true);
						},
						error: function(result) {
							$.messager.alert("失败", "弃审失败");
						}
					});
				}
			});
		}

		function print() { //打印
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可打印！");
				return;
			}
			if(currid == AddFlag || isVerify != 1) {
				$.messager.alert('警示', "该单据未审核，不可以打印！");
				return;
			}
			var pLocation = "TenantChargePrint.html?id=" + currid
			window.open(pLocation);
		}

		function loadLocal(localid) {
			var _url = RemoteLinkAddress + '/frozen/charge/findbyid.do?ID=' + localid;
			getLocalData(_url);
		}

		function cls() {
			$('#ff').form('reset');
		}

		function getSaveData() {
			var data = submitFormData();
			submitData(data);
		}

		function getUpdateData() {
			var data = submitFormData();
			submitData(data);
		}

		function submitData(_data) {
			lockButton("lock");
			var _url = "";
			if(currid == AddFlag) {
				_url = saveUrl;
			} else {
				_url = RemoteLinkAddress + "/frozen/charge/update.do";
			}
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: _data,
				type: "POST",
				success: function(result) {
					lockButton("unlock");
					if(result.msg == "charged")
					{
						$.messager.alert("提示信息", "单据已经收费,不能重复收费");
					}
					else
					{
						$.messager.alert("提示信息", "收费成功");
					}
				},
				error: function(result) {
					$.messager.alert("错误信息", "收费失败");
				}
			});
		}

		function getLocalData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						_dataPage = result;
						isVerify = result.ISVERIFY;
						verifyStatus_Market(isVerify, true);
						currid = result.ID;
						currPage = result.ID;
						getFormData(result);
						getDialogFooterData(result);
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}
	</script>

</html>